//
//  CJSStoryHeadView.m
//  GoTraveling
//
//  Created by 陈金山 on 15/12/25.
//  Copyright © 2015年 开发华佗. All rights reserved.
//

#import "CJSStoryHeadView.h"
#import "UIImageView+WebCache.h"
#import "User.h"
#import "WSTools.h"

@interface CJSStoryHeadView ()

@property (nonatomic, retain) UIImageView *headImageView;

@property (nonatomic, retain) UILabel *nameLabel;

@property (nonatomic, retain) UILabel *contentLabel;

@end

@implementation CJSStoryHeadView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews {
    
    //头像
    self.headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 30, 60, 60)];
    self.headImageView.backgroundColor = [UIColor blueColor];
    self.headImageView.layer.cornerRadius = 30;
    self.headImageView.layer.masksToBounds = YES;
    [self addSubview:_headImageView];
    
    float x = self.headImageView.frame.origin.x + self.headImageView.frame.size.width;
    
    //用户名
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(x + 20, self.headImageView.frame.origin.y, SCREEN_WIDTH - x, self.headImageView.frame.size.height)];
    self.nameLabel.font = [UIFont systemFontOfSize:20 weight:0.5];
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"states"] isEqualToString:@"1"]) {
        
        self.nameLabel.textColor = [UIColor colorWithRed:0.78 green:0.78 blue:0.79 alpha:1];
    }
    else {
        
        self.nameLabel.textColor = [UIColor colorWithRed:0.15 green:0.16 blue:0.18 alpha:1];
    }
    [self addSubview:_nameLabel];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(20, self.headImageView.frame.size.height + 60, SCREEN_WIDTH - 40, 1)];
    lineView.backgroundColor = [UIColor colorWithRed:0.88 green:0.87 blue:0.85 alpha:1];
    [self addSubview:lineView];
    
    //内容
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.headImageView.frame.size.height + 100, SCREEN_WIDTH - 40, 100)];
    self.contentLabel.font = [UIFont systemFontOfSize:20 weight:0.1];
    self.contentLabel.textColor = [UIColor colorWithRed:0.28 green:0.28 blue:0.28 alpha:1];
    self.contentLabel.numberOfLines = 0;
    [self addSubview:_contentLabel];
}

- (void)setStory:(CJSStroy *)story {
    
    _story = story;
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:[[self.story users] avatar_m]] placeholderImage:[UIImage imageNamed:@"avatar_placeholder_26"]];
    self.nameLabel.text = [[self.story users] name];
    self.contentLabel.text = [self.story text];
    [self.contentLabel sizeToFit];
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
